//
//  Image.m
//  代理模式
//
//  Created by flannery on 2018/12/18.
//  Copyright © 2018年 flannery. All rights reserved.
//

#import "Image.h"

#pragma ======
@interface RealImage ()
@property (nonatomic, strong) NSString * fileName;
@end
@implementation RealImage
- (instancetype)initWithFileName:(NSString *)fileName
{
    self = [super init];
    if (self) {
        self.fileName = fileName;
        [self loadFromDisk:fileName];
    }
    return self;
}

- (void)display {
    NSLog(@"Displaying -> %@", self.fileName);
}


-(void) loadFromDisk:(NSString*)fileName{
    NSLog(@"Loading -> %@", fileName);
}
@end

#pragma =======
@interface ProxyImage ()
@property (nonatomic, strong) NSString * fileName;
@property (nonatomic, strong) RealImage * realImage;
@end
@implementation ProxyImage

- (instancetype)initWithFileName:(NSString *)fileName
{
    self = [super init];
    if (self) {
        self.fileName = fileName;
    }
    return self;
}

- (void)display {
    if(!self.realImage) {
        self.realImage = [[RealImage alloc]initWithFileName:self.fileName];
    }
    [self.realImage display];
}

@end
